package com.nanfang51g3.ckz.ui.fragment.fill;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.nanfang51g3.ckz.R;
import com.nanfang51g3.ckz.ui.money.fill.FillInContract;
import com.nanfang51g3.ckz.ui.money.preview.PreviewMoneyInfoActivity;
import com.nanfang51g3.ckz.utils.KLog;
import com.nanfang51g3.ckz.utils.SPUtil;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/4/28.
 */
public class FillInBankFragment extends Fragment {
    public static FillInContract.FillInActionsListener mFillInActionsListener;

    @Bind(R.id.tv_fill_in_bank_withdraw_name)
    TextView tvFillInBankWithdrawName;
    @Bind(R.id.tv_fill_in_bank_withdraw_id)
    TextView tvFillInBankWithdrawId;
    @Bind(R.id.relative_fill_in_bank)
    RelativeLayout relativeFillInBank;
    String bank_name;
    String bank_card;


    public static FillInBankFragment newInstance(Context context, FillInContract.FillInActionsListener fillInActionsListener) {
        FillInBankFragment fillInBankFragment = new FillInBankFragment();
        Bundle args = new Bundle();
        String bank_name = (String) SPUtil.get(context, "bank_name", "暂未填写");
        String bank_card = (String) SPUtil.get(context, "bank_card", "暂未填写");
        args.putString("bank_name", bank_name);
        args.putString("bank_card", bank_card);
        KLog.i("Evd", "bank_name=" + bank_name);
        KLog.i("Evd", "bank_card=" + bank_card);
        fillInBankFragment.setArguments(args);
        mFillInActionsListener = fillInActionsListener;
        KLog.i("Evd", fillInActionsListener == null ? "fillInActionsListener - 1" : "fillInActionsListener - 0");
        return fillInBankFragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fill_in_bank_fragment, null);
        ButterKnife.bind(this, view);
        Bundle bundle = getArguments();
        bank_name = bundle.getString("bank_name");
        bank_card = bundle.getString("bank_card");
        KLog.i("Evd", "bank_name=" + bank_name);
        KLog.i("Evd", "bank_card=" + bank_card);
        KLog.i("Evd", mFillInActionsListener == null ? "mWithdrawActionsListener - 1" : "mWithdrawActionsListener - 0");
        tvFillInBankWithdrawName.setText(bank_name);
        String value = bank_card.substring(bank_card.length() - 4, bank_card.length());
        tvFillInBankWithdrawId.setText("尾号：" + value);
        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        String bank_name = (String) SPUtil.get(getActivity(), "bank_name", "暂未填写");
        String bank_card = (String) SPUtil.get(getActivity(), "bank_card", "暂未填写");
        tvFillInBankWithdrawName.setText(bank_name);
        String value = bank_card.substring(bank_card.length() - 4, bank_card.length());
        tvFillInBankWithdrawId.setText("尾号：" + value);
    }

    @OnClick(R.id.relative_fill_in_bank)
    public void relative_fill_in_bank(View view) {
        startActivity(new Intent(getActivity(), PreviewMoneyInfoActivity.class));
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);

    }
}
